package com.ctshk.app.user.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.user.dto.PassengerDTO;
import com.ctshk.rpc.user.dto.PassengerListDTO;
import com.ctshk.rpc.user.dto.UserMessageDTO;
import com.ctshk.rpc.user.dto.UserMessageListDTO;
import com.ctshk.rpc.user.req.PassengerPageReq;
import com.ctshk.rpc.user.req.PassengerReq;
import com.ctshk.rpc.user.req.UserMessagePageReq;
import com.ctshk.rpc.user.req.UserMessageReq;
import com.ctshk.rpc.user.service.IUserMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.concurrent.CompletableFuture;

/**
 * <p>
 *  用户消息前端控制器
 * </p>
 *
 * @author 李新科
 * @date 2021/5/17 17:30
 */
@Api(value="用户消息", tags="用户消息")
@RestController
@RequestMapping("/userMessage")
public class UserMessageController extends AppBaseController {

    @DubboReference
    private IUserMessageService userMessageService;

    @ApiOperation(value="消息列表", notes="消息列表")
    @OperationLogAnnotation(operModul = OperationLogModel.USER, operType = OperationLogType.QUERY, operTitle = "消息列表", operDesc = "消息列表")
    @PostMapping("/list")
    public Result<PageResponse<UserMessageListDTO>> queryPage(@RequestBody @Valid UserMessagePageReq req) throws Exception{
        TokenUser currentUser = getCurrentUser();
        req.setUserId(currentUser.getId());
        return userMessageService.queryPage(req);
    }

    @ApiOperation(value="消息详情", notes="消息详情")
    @OperationLogAnnotation(operModul = OperationLogModel.USER, operType = OperationLogType.QUERY, operTitle = "消息详情", operDesc = "消息详情")
    @PostMapping("/detail/{id}")
    public Result<UserMessageDTO> detail(@PathVariable @NotNull(message = "id不能为空")
                                       @ApiParam(name="id",required = true) Long id) throws Exception{
        TokenUser currentUser = getCurrentUser();
        return userMessageService.detail(id,currentUser.getId());
    }

    @ApiOperation(value="测试新增消息", notes="测试新增消息")
    @OperationLogAnnotation(operModul = OperationLogModel.USER, operType = OperationLogType.ADD, operTitle = "测试新增消息", operDesc = "测试新增消息")
    @PostMapping("/notify")
    public Result notify(@RequestBody @Valid UserMessageReq req) throws Exception{
        userMessageService.notify(req);
        return Result.success();
    }
}
